import 'package:flutter/material.dart';

import 'window.dart';

class IWindowView extends StatefulWidget {
  const IWindowView({
    super.key,
    this.child,
  });
  final Widget? child;
  @override
  State<IWindowView> createState() => _IWindowViewState();
}

class _IWindowViewState extends State<IWindowView> {
  late OverlayEntry _overlayEntry;
  @override
  void initState() {
    _overlayEntry = OverlayEntry(builder: (ctx) {
      return Stack(
        children: List.generate(IWindow.instance.keys.length, (index) {
          var name = IWindow.instance.keys[index];
          return IWindow.instance.getW(name) ?? const SizedBox();
        }),
      );
    });
    IWindow.instance.oe = _overlayEntry;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Overlay(
        initialEntries: [
          OverlayEntry(
            builder: (BuildContext context) {
              return widget.child ?? const SizedBox();
            },
          ),
          _overlayEntry,
        ],
      ),
    );
  }
}
